﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="OrmSmackdown.NHibernate.Person, Ormsmackdown" table="People">
    <id name="PersonId" type="Int32">
      <generator class="identity" />
    </id>
    <discriminator column="UserType" type="String" insert="true" not-null="false" />
    
    <property name="FirstName" not-null="true" type="String"></property>
    <property name="LastName" not-null="true" type="String"></property>
    <property name="Email" not-null="true" type="String"></property>
    
    <many-to-one name="Role" column="RoleId" fetch="join" not-null="false" />

    <subclass name="OrmSmackdown.NHibernate.Contact, Ormsmackdown" discriminator-value='CN'>
      <many-to-one name="Company" column="CompanyId" fetch="join" not-null="false" />
    </subclass>

    <subclass name="OrmSmackdown.NHibernate.User, Ormsmackdown" discriminator-value='US'>
      <bag name="Portals" table="PortalPeopleXref">
        <key column="PersonId" />
        <many-to-many class="OrmSmackdown.NHibernate.Portal, Ormsmackdown" column="PortalId" />
      </bag>
      <many-to-one name="Manager" column="ManagerPersonId" fetch="join" not-null="false" />
    </subclass>
  </class>
</hibernate-mapping>
